#!/bin/bash

# shellcheck disable=SC1091
. ../../lib/shflags

DEFINE_string "password" "12345678" 'root password' 'p'
DEFINE_integer "expose" 3308 'expose port' 'e'
DEFINE_string "version" '8.4.5' 'mysql version' 'v'
# 解析命令行参数
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

echo "password, ${FLAGS_password}! expose ${FLAGS_expose} version ${FLAGS_version} ."

echo "stop container"
docker stop db && docker rm db


# 如果要安装 5.7 则将 mysql:8.0 => mysql:5.7.44 即可。
echo "start container"
docker run --restart=always -d \
    -p "${FLAGS_expose}":3306 \
    --name db \
    -e MYSQL_ROOT_PASSWORD="${FLAGS_password}" mysql:"${FLAGS_version}"
